import { Body, Controller, Get, Param, Post, Req, Res, UseGuards } from '@nestjs/common';
import { AuthService } from './auth.service';
import { Request } from 'express';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { LoginDto } from './dto/auth.dto';
import { LocalGuard } from 'src/common/guards/local.guard';
import { JwtGuard } from 'src/common/guards/jwt.guard';

@Controller('auth')
@ApiTags('auth模块')
export class AuthController {
  constructor(private readonly authService: AuthService) {}

  @Get('captcha')
  @ApiOperation({ summary: '获取验证码' })
  createCaptcha() {
    return this.authService.createCaptcha();
  }

  @UseGuards(LocalGuard)
  @Post('login')
  @ApiOperation({ summary: '登录' })
  login(@Req() req: Request, @Body() body: LoginDto) {
    return this.authService.login(req, body);
  }

  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  @Get('logout')
  @ApiOperation({ summary: '退出登录' })
  logout(@Req() req: Request) {
    return this.authService.logout(req);
  }
}
